package kr.hkit.androidcomplete02.ch16;

import java.util.Calendar;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class ShowDialogEx extends Activity {
	final static int SAMPLE_DLG = 0;
	final static int QUESTION_DLG = 1;

	protected void onCreate(Bundle savedInstanceState) {
		Log.d("ShowDialogEx", "onCreate");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_showdialogex);
	}

	public void mOnClick(View v) {
		switch (v.getId()) {
		case R.id.ch16_showdialog_btn:
			showDialog(SAMPLE_DLG);
			break;
		case R.id.ch16_showdialog_btn2:
			showDialog(QUESTION_DLG);
			break;
		}
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		Log.d("ShowDialogEx", "onCreateDialog"
				+ (id == 0 ? "SAMPLE_DLG" : "QUESTION_DLG"));
		switch (id) {
		case SAMPLE_DLG:
			return new AlertDialog.Builder(this).setTitle("알립니다")
					.setMessage("대화상자를 열었습니다").setIcon(R.drawable.ic_launcher)
					.setPositiveButton("닫기", null).create();
		case QUESTION_DLG:
			return new AlertDialog.Builder(this).setTitle("질문")
					.setMessage("밥 먹었어요?").setPositiveButton("먹었다", null)
					.setNegativeButton("굶었다", null).create();
		}
		return null;
	}

	@Override
	protected void onPrepareDialog(int id, Dialog dialog) {
		Log.d("ShowDialogEx", "onPrepareDialog"
				+ (id == 0 ? "SAMPLE_DLG" : "QUESTION_DLG"));
		switch (id) {
		case SAMPLE_DLG:
			break;
		case QUESTION_DLG:
			Calendar cal = Calendar.getInstance();
			String stime = String.format("%d시 %d분 %d초", cal.get(Calendar.HOUR),
					cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
			dialog.setTitle(stime);
			break;
			
		}
	}
}
